package com.cz.background.controller.common;


import com.cz.background.common.dto.PageResponseResult;
import com.cz.background.dto.common.user.AddUserDTO;
import com.cz.background.dto.common.user.UpdateUserDTO;
import com.cz.background.dto.common.user.UpdateUserStatusDTO;
import com.cz.background.dto.common.user.UserQueryDTO;
import com.cz.background.entity.common.SysUser;
import com.cz.background.service.common.SysUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/user")
@Tag(name = "用户管理")
public class UserController {


    @Autowired
    private SysUserService userService;

    @PostMapping("page")
    @Operation(summary = "分页查询 用户列表")
    public PageResponseResult<SysUser> page(@RequestBody UserQueryDTO userQueryDTO) {
       return userService.queryUserPage(userQueryDTO);
    }


    @PostMapping("addUser")
    @Operation(summary = "新增用户")
    public void addUser(@RequestBody @Valid AddUserDTO addUserDTO) {
        userService.addUser(addUserDTO);
    }

    @PostMapping("delUser")
    @Operation(summary = "删除用户")
    public void deleteUser(@RequestBody List<String> ids) {
        userService.delUser(ids);
    }


    @PostMapping("updateUser")
    @Operation(summary = "更新用户")
    public void updateUser(@RequestBody @Valid UpdateUserDTO updateUserDTO) {
        userService.updateUser(updateUserDTO);
    }


    @PostMapping("updateUserStatus")
    @Operation(summary = "更新用户状态")
    public void updateUserStatus(@RequestBody @Valid UpdateUserStatusDTO updateUserStatusDTO) {
        userService.updateUserStatus(updateUserStatusDTO);
    }

}
